<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>
        openGauss自动化可靠性-CI连跑分析报告
    </title>
    <style type="text/css">
            LogTitle {
                display: block;
                background-color: #b6d7a8;
                padding: 10px; }

            .table {
                table-layout:fixed;
                word-break:break-all;}

            .modal.fade.in {
                top: 20%;
            }

            .ms-drop li {
                line-height: 18px;
            }

            .ms-drop span {
                margin-left: 5px;
            }
    </style>
</head>
<body>
{% extends 'base.html' %}
{% block body_part %}
<LogTitle><em style="font-size: 20px;"><b>报告汇总</b></em><br></LogTitle>
<table id="sum_table" class="table table-hover">
</table>
<br>

<LogTitle><em style="font-size: 20px;"><b>详细数据</b></em></LogTitle>
<br>
<form class="form-inline" role="form" id="toolbar">
    <div class="form-group">
        <label style="color: black;margin-left: 10px;">
            执行环境:
        </label>
        <select class="form-control" name="filterOS" id="filterOS">
            <option value="all" selected>
                全部
            </option>
            <option value="x86_CentOS">
                x86_centos
            </option>
            <option value="x86_openEuler">
                x86_openEuler
            </option>
            <option value="arm_openEuler">
                arm_openEuler
            </option>
        </select>
    </div>
    <div class="form-group">
        <label style="color: black;margin-left: 10px;">
            测试套名称:
        </label>
        <input type="text" class="form-control" name="schd" id="schd">
        <label style="color: black;margin-left: 10px;">
            用例名称:
        </label>
        <input type="text" class="form-control" name="tcname" id="tcname">
        <label style="color: black;margin-left: 10px;">
            测试责任人:
        </label>
        <select name="filterTester" id="filterTester"
                style="width:150px;height:30px;margin-left: 20px;"
                multiple="multiple">
            <option value="裴琳倩">裴琳倩</option>
            <option value="郝梦">郝梦</option>
            <option value="张欢">张欢</option>
            <option value="宁雅黎">宁雅黎</option>
            <option value="侯少龙">侯少龙</option>
            <option value="屈敏">屈敏</option>
            <option value="李鑫">李鑫</option>
            <option value="郭维彪">郭维彪</option>
            <option value="仇颖">仇颖</option>
            <option value="李岩松">李岩松</option>
            <option value="张翱">张翱</option>
            <option value="白小丽">白小丽</option>
            <option value="成嘉琦">成嘉琦</option>
            <option value="李卓">李卓</option>
            <option value="姚康">姚康</option>
            <option value="王珂">王珂</option>
            <option value="夏琦">夏琦</option>
            <option value="邹佳良">邹佳良</option>
            <option value="雷帅">雷帅</option>
        </select>
    </div>
    <div class="form-group">
        <label style="color: black;margin-left: 10px;">
            执行结果:
        </label>
        <select class="form-control" name="filterResult" id="filterResult">
            <option value="all" selected>
                全部
            </option>
            <option value="ok">
                成功
            </option>
            <option value="er">
                失败
            </option>
            <option value="to">
                阻塞
            </option>
        </select>

        <button type="button" class="btn btn-default" id="btn_search">
            查询
        </button>

        <button type="button" class="btn btn-default" id="btn_adv_query">
            更多查询
        </button>

        <button type="button" class="btn btn-default" id="btn_edit">
            编辑
        </button>
    </div>
</form>

<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h4 class="modal-title" id="myModalLabel">编辑失败用例信息</h4>
            </div>
            <div class="modal-body">
                <form role="form" id="edit_form">
                    <div class="form-group">
                        <label for="fail_reason">失败原因</label>
                        <input type="text" id="fail_reason"
                               class="form-control"
                               placeholder="请输入失败原因：">

                        <label for="resolve_way">解决办法</label>
                        <input type="text" id="resolve_way"
                               class="form-control"
                               placeholder="请输入解决办法：">

                        <label for="tc_status">问题类型</label>
                        <select class="form-control" name="problem_type"
                                id="problem_type">
                            <option value="bug">bug</option>
                            <option value="用例问题" selected>用例问题</option>
                            <option value="环境问题">环境问题</option>
                            <option value="其他用例影响">其他用例影响</option>
                            <option value="研发代码变更">研发代码变更</option>
                            <option value="yat问题">yat问题</option>
                        </select>

                        <label for="resolve_way">issue编号</label>
                        <input type="text" id="issue_no"
                               class="form-control"
                               placeholder="请输入issue编号：">

                        <label for="resolve_way">开发责任人</label>
                        <input type="text" id="develop_owner"
                               class="form-control"
                               placeholder="请输入开发责任人：">

                        <label for="resolve_way">测试责任人</label>
                        <input type="text" id="test_owner"
                               class="form-control"
                               placeholder="请输入测试责任人：">

                        <label for="tc_status">状态</label>
                        <select class="form-control" name="tc_status"
                                id="tc_status">
                            <option value="未解决" selected>未解决</option>
                            <option value="已解决">已解决</option>
                            <option value="处理中">处理中</option>
                            <option value="待确认">待确认</option>
                            <option value="已合入">已合入</option>
                            <option value="未合入">未合入</option>
                        </select>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary"
                        id="model_confirm">提交更改
                </button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div> <!-- /.modal -->
<!-- 查询模态框（Modal） -->
<div class="modal fade" id="queryModal" tabindex="-1" role="dialog"
     aria-labelledby="queryModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">
                </button>
                <h4 class="modal-title" id="queryModalLabel">更多查询</h4>
            </div>
            <div class="modal-body">
                <form role="form" id="query_form">
                    <div class="form-group">
                        <label for="date_type">选择查询类型</label>
                        <select class="form-control" name="date_type"
                                id="date_type">
                            <option value="run" selected>当日数据</option>
                            <option value="his">历史数据</option>
                        </select>
                        <label for="create_time">开始时间</label>
                        <input type="text" autocomplete="off"
                               class="form-control start_datetime"
                               placeholder="开始时间"
                               name="create_time" id="create_time">
                        <label for="end_time">开始时间</label>
                        <input type="text" autocomplete="off"
                               class="form-control end_datetime"
                               placeholder="结束时间"
                               name="end_time" id="end_time">
                        <label for="failed_reason">失败原因</label>
                        <input type="text" id="failed_reason"
                               class="form-control"
                               placeholder="请输入：支持模糊匹配，不区分大小写">
                        <label for="solution">解决办法</label>
                        <input type="text" id="solution"
                               class="form-control"
                               placeholder="请输入：支持模糊匹配，不区分大小写">
                        <label for="tc_status">问题类型</label>
                        <select class="form-control" name="problem_type1"
                                id="problem_type1">
                            <option value="all" selected>all</option>
                            <option value="bug">bug</option>
                            <option value="用例问题">用例问题</option>
                            <option value="环境问题">环境问题</option>
                            <option value="其他用例影响">其他用例影响</option>
                            <option value="研发代码变更">研发代码变更</option>
                            <option value="yat问题">yat问题</option>
                        </select>
                        <label for="issue_no1">issue编号</label>
                        <input type="text" id="issue_no1"
                               class="form-control"
                               placeholder="请输入：支持模糊匹配，不区分大小写">
                        <label for="develop_owner1">开发责任人</label>
                        <input type="text" id="develop_owner1"
                               class="form-control"
                               placeholder="请输入：支持模糊匹配，不区分大小写">
                        <label for="status">状态</label>
                        <select class="form-control" name="status"
                                id="status">
                            <option value="all" selected>all</option>
                            <option value="未解决">未解决</option>
                            <option value="已解决">已解决</option>
                            <option value="处理中">处理中</option>
                            <option value="待确认">待确认</option>
                            <option value="已合入">已合入</option>
                            <option value="未合入">未合入</option>
                        </select>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary"
                        id="model_query">开始查询
                </button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div> <!-- /.modal -->


<table id="info_table" class="table table-hover">
</table>
<script type="text/javascript">
        $('#filterTester').multipleSelect({
            selectAll: true, //是否显示全部复选框，默认显示
            selectAllText: "选择全部", //选择全部的复选框的text值
            allSelected: "all", //全部选中后显示的值
            placeholder: "请选择"
        });

	    var sum_table = $("#sum_table");
		sum_table.bootstrapTable("destroy").bootstrapTable({
			url: "{% url 'get_sum_data' %}",
			dataType: "json",
			sidePagination: "server",
			method: 'get',
			columns: [{
				field: "id",
				title: "编号",
				align: 'center',
				width: "5%",
				sortable: false,
				visible: false
			},{
			    field: "feature_name",
				title: "用例类别",
				align: 'center',
				width: "5%",
				sortable: false,
			},{
			    field: "run_os",
				title: "执行环境",
				align: 'center',
				width: "5%",
				sortable: false,
			},{
			    field: "success_rate",
				title: "成功率(%)",
				align: 'center',
				width: "5%",
				sortable: false,
			},{
			    field: "total_num",
				title: "用例总数(个)",
				align: 'center',
				width: "5%",
				sortable: false,
			},{
			    field: "pass_num",
				title: "用例通过(个)",
				align: 'center',
				width: "5%",
				sortable: false,
			},{
			    field: "fail_num",
				title: "用例失败(个)",
				align: 'center',
				width: "5%",
				sortable: false,
			},{
			    field: "block_num",
				title: "用例阻塞(个)",
				align: 'center',
				width: "5%",
				sortable: false,
			},{
			    field: "core_num",
				title: "core数量",
				align: 'center',
				width: "5%",
				sortable: false,
			},{
			    field: "start_time",
				title: "开始时间",
				align: 'center',
				width: "5%",
				sortable: false,
				formatter: function(value, row, index) {
                    return value.substring(0,19)
                },
			},{
			    field: "run_time",
				title: "运行时间",
				align: 'center',
				width: "5%",
				sortable: false,
				formatter: function(value, row, index) {
				    var str = value.split(/:/);
				    var run_time = str[0] + 'H' + str[1] + 'M' + str[2] + 'S';
                    return run_time
                },
			}],
			queryParams: function(params) {
				var temp = {
					feature: "reliability",
					tier: 3
				};
				return temp;
			},
			})

		var info_table = $("#info_table");
		info_table.bootstrapTable("destroy").bootstrapTable({
			url: "{% url 'get_info_data' %}",
			dataType: "json",
			method: 'get',
			toolbar: '#toolbar',
			striped: true,
			cache: false,
			pagination: true,
			sortable: true,
			sortOrder: "asc",
			sidePagination: "server",
			pageNumber: 1,
			pageSize: 25,
			pageList: [10, 25, 50, 100, 1000, 2000],
			search: false,
			strictSearch: true,
			showColumns: true,
			showRefresh: true,
			minimumCountColumns: 2,
			clickToSelect: true,
			uniqueId: "ID",
			showToggle: false,
			cardView: false,
			detailView: false,
			height: 800,
			rowStyle: function (row, index) {
				    var style;
				    if (row.run_result == "成功") {
				        style = {css:{'color': 'green'}};
				    } else if (row.run_result == "失败") {
				        style = {css:{'color': 'red'}};
				    } else {
				        style = {css:{'color': 'gray'}};
				    }
                    return style;
                },
			columns: [{
				checkbox: true,
			},
			{
				field: "id",
				title: "编号",
				width: "5%",
			    align: 'center',
				sortable: false,
				visible: false,
			},
			{
				field: "run_os",
				title: "执行环境",
				align: 'center',
				width: "8%",
				sortable: false,
			},
			{
				field: "model_name",
				title: "测试套名称",
				align: 'center',
				width: "10%",
				sortable: false,
			},
			{
				field: "tc_name",
				title: "用例名称",
				align: 'center',
				width: "20%",
				sortable: false,
			},
			{
			    field: "run_result",
				title: "执行结果",
				align: 'center',
				width: "7%",
				sortable: true,
			},
			{
				field: "start_time",
				title: "开始时间",
				align: 'center',
				sortable: true,
				width: "10%",
				visible: false,
			},
			{
				field: "run_time",
				title: "运行时长",
				align: 'center',
				width: "5%",
			},
			{
				field: "failed_reason",
				title: "失败原因",
				align: 'left',
				width: "10%",
				formatter: function(value, row, index) {
                    if (value == "") {
                        return '添加';
                    }else{
                        return value;
                    }
                },
                editable: {
                    type: 'text',
                    title: '失败原因',
                    validate: function (value) {
                        if (!value) {
                            return '不能为空！';
                        }
                    }
                }
			},
			{
				field: "solution",
				title: "解决办法",
				align: 'left',
				width: "8%",
				formatter: function(value, row, index) {
                    if (value == "") {
                        return '添加';
                    }else{
                        return value;
                    }
                },
                editable: {
                    type: 'text',
                    title: '解决办法',
                    validate: function (value) {
                        if (!value) {
                            return '不能为空！';
                        }
                    }
                }
			},
			{
				field: "problem_type",
				title: "问题类型",
				align: 'center',
				width: "7%",
				sortable: true,
				formatter: function(value, row, index) {
				    console.log(value)
                    if (value == "") {
                        return '用例问题';
                    }else{
                        return value;
                    }
                },
				editable: {
                    type: 'select',
                    title: '问题类型',
                    source: [
                        {value:"bug",text:"bug"},
                        {value:"用例问题",text:"用例问题"},
                        {value:"环境问题",text:"环境问题"},
                        {value:"其他用例影响",text:"其他用例影响"},
                        {value:"研发代码变更",text:"研发代码变更"},
                        {value:"yat问题",text:"yat问题"}]
                }
			},
			{
				field: "issue_no",
				title: "issue编号",
				align: 'center',
				width: "6%",
				formatter: function(value, row, index) {
                    if (value == "") {
                        return '添加';
                    }else{
                        return value;
                    }
                },
                editable: {
                    type: 'text',
                    title: 'issue编号',
                    validate: function (value) {
                        if (!value) {
                            return '不能为空！';
                        }
                    }
                }
			},
			{
				field: "develop_owner",
				title: "开发责任人",
				align: 'center',
				width: "6%",
				formatter: function(value, row, index) {
                    if (value == "") {
                        return '添加';
                    }else{
                        return value;
                    }
                },
                editable: {
                    type: 'text',
                    title: '开发责任人',
                    validate: function (value) {
                        if (!value) {
                            return '不能为空！';
                        }
                    }
                }
			},
			{
				field: "test_owner",
				title: "测试责任人",
				align: 'center',
				width: "6%",
				formatter: function(value, row, index) {
                    if (value == "") {
                        return '添加';
                    }else{
                        return value;
                    }
                },
                editable: {
                    type: 'text',
                    title: '测试责任人',
                    validate: function (value) {
                        if (!value) {
                            return '不能为空！';
                        }
                    }
                }
			},
			{
				field: "status",
				title: "状态",
				sortable: true,
				align: 'center',
				width: "5%",
				formatter: function(value, row, index) {
                    if (value == "") {
                        return '未解决';
                    }else{
                        return value;
                    }
                },
				editable: {
                    type: 'select',
                    title: '状态',
                    source: [
                        {value:"未解决",text:"未解决"},
                        {value:"已解决",text:"已解决"},
                        {value:"处理中",text:"处理中"},
                        {value:"待确认",text:"待确认"},
                        {value:"已合入",text:"已合入"},
                        {value:"未合入",text:"未合入"}]
                }
			},
			{
			    field: "jenkins_link",
				title: "jenkins日志",
				align: 'center',
				width: "7%",
				sortable: false,
				formatter: function(value, row, index) {
				    var link = "<a href='" + value + "' target='_blank'>点击跳转</a>"
				    return link
				}
			},
			{
			    field: "log_link",
				title: "yat日志",
				align: 'center',
				width: "7%",
				sortable: false,
				formatter: function(value, row, index) {
				    var link = "<a href='" + value + "' target='_blank'>点击跳转</a>"
				    return link
				}
			},
			{
				field: 'editer',
				title: '编辑',
				width: 120,
				align: 'center',
				valign: 'middle',
				visible: false,
				formatter: function(value, row, index) {
					return "<a href='javascript:;' class='btn btn-xs blue' onclick='editRow(${index})' title='编辑'><span class='glyphicon glyphicon-pencil'></span></a>"
				}
			}],
			onEditableSave: function (field, row, oldValue, $el) {
                $("#info_table").bootstrapTable("resetView");
                $.ajax({
                    type: "post",
                    url: "{% url 'update_info' %}",
                    data: {
                        "id": row.id,
                        "failed_reason": row.failed_reason,
                        "solution": row.solution,
                        "problem_type": row.problem_type,
                        "issue_no": row.issue_no,
                        "develop_owner": row.develop_owner,
                        "test_owner": row.test_owner,
                        "status": row.status,
                        "feature":  "reliability",
                        "tier": 3
                        },
                    dataType: 'JSON',
                    success: function (data, status) {
                        if (status == 'success') {
                            alert('修改成功');
                        }else {
                            alert('修改失败');
                        }
                    },
                    complete: function (data, status) {
                        $("#info_table").bootstrapTable("refresh");
                    }
                });
            },
			queryParams: function(params) {
				var temp = {
					limit: params.limit,
					offset: params.offset,
					sort: params.sort,
					order: params.order,
					feature: "reliability",
					run_os: $.trim($('#filterOS').val()),
					tester: $.trim($('#filterTester').val()),
					run_result: $.trim($('#filterResult').val()),
					problem_type: $.trim($('#filterProblemType').val()),
					model_name: $.trim($('#schd').val()),
					tc_name: $.trim($('#tcname').val()),
                    failed_reason: $.trim($('#failed_reason').val()),
                    solution: $.trim($('#solution').val()),
                    problem_type: $.trim($('#problem_type1').val()),
                    issue_no: $.trim($('#issue_no1').val()),
                    develop_owner: $.trim($('#develop_owner1').val()),
                    status: $.trim($('#status').val()),
                    date_type: $.trim($('#date_type').val()),
                    create_time: $.trim($('#create_time').val()),
                    end_time: $.trim($('#end_time').val())
				};
				return temp;
			},
		});

		//操作栏的格式化
		function actionFormatter(value, row, index) {
			var id = value;
			var result = "";
			result += "<a href='javascript:;' class='btn btn-xs green' onclick=\"EditViewById('" + id + "', view='view')\" title='查看'><span class='glyphicon glyphicon-search'></span></a>";
			result += "<a href='javascript:;' class='btn btn-xs blue' onclick=\"EditViewById('" + id + "')\" title='编辑'><span class='glyphicon glyphicon-pencil'></span></a>";
			result += "<a href='javascript:;' class='btn btn-xs red' onclick=\"DeleteByIds('" + id + "')\" title='删除'><span class='glyphicon glyphicon-remove'></span></a>";
			return result;
		}

		$('#btn_search').click(function() {
			$('#info_table').bootstrapTable('refreshOptions', {pageNumber:1, pageSize:25});
		})

		$('#btn_edit').click(function() {
		    $('#myModal').modal('show');
		})

		$('#btn_adv_query').click(function() {
		    $('#date_type').val("run");
		    $('#create_time').val("");
		    $('#end_time').val("");
		    $('#create_time').attr('disabled', 'disabled');
            $('#end_time').attr('disabled', 'disabled');
            $('#queryModal').modal('show');
		})

		$('#date_type').change(function() {
		    var type_val = $.trim($('#date_type').val());
		    if (type_val == 'run') {
		        $('#create_time').val("");
		        $('#end_time').val("");
                $('#create_time').attr('disabled', 'disabled');
                $('#end_time').attr('disabled', 'disabled');
		    } else {
		        $('#create_time').removeAttr('disabled');
                $('#end_time').removeAttr('disabled');
		    }
		})

		$("#create_time").datetimepicker({
            language: "zh-CN",
            format: "yyyy-mm-dd hh:ii:ss",
            minView: "hour",
            autoclose: true,
            todayBtn: true
        }).on("changeDate", function (ev) {
            if (ev.date) {
                $("#end_time").datetimepicker('setStartDate', new Date(ev.date.valueOf()));
            } else {
                $("#end_time").datetimepicker('setStartDate', null);
            }
        });

        $("#end_time").datetimepicker({
            language: "zh-CN",
            format: "yyyy-mm-dd hh:ii:ss",
            minView: "hour",
            autoclose: true,
            todayBtn: true
        }).on("changeDate", function (ev) {
            if (ev.date) {
                $("#create_time").datetimepicker('setEndDate', new Date(ev.date.valueOf()));
            } else {
                $("#create_time").datetimepicker('setEndDate', new Date());
            }
        });

		$('#model_query').click(function() {
		    $('#queryModal').modal('hide');
		    $('#info_table').bootstrapTable('refreshOptions', {pageNumber:1, pageSize:25});
		})

		$('#model_confirm').click(function() {
            var rows = $('#info_table').bootstrapTable('getSelections');
            if (rows.length == 0) {
                alert("请选择要编辑的数据");
                $('#myModal').modal('hide');
                return;
            }

            var ids = '';
            $.each(rows, function(i, row) {
                ids += row['id'] + ",";
            })
            ids = ids.substring(0, ids.length -1);
            console.log($.trim($('#problem_type').val()))
            $.ajax({
                type: "post",
                url: "{% url 'update_info' %}",
                data: {
                    "ids": ids,
                    "failed_reason": $.trim($('#fail_reason').val()),
                    "solution": $.trim($('#resolve_way').val()),
                    "problem_type": $.trim($('#problem_type').val()),
                    "issue_no": $.trim($('#issue_no').val()),
                    "develop_owner": $.trim($('#develop_owner').val()),
                    "test_owner": $.trim($('#test_owner').val()),
                    "status": $.trim($('#tc_status').val()),
                    "feature": "reliability",
                    "tier": 3
                    },
                dataType: 'JSON',
                success: function (data, status) {
                    if (status == 'success') {
                        alert('修改成功');
                    }else {
                        alert('修改失败');
                    }
                },
                complete: function (data, status) {
                    $("#info_table").bootstrapTable("refresh");
                }
            });
            $('#myModal').modal('hide');
		})
</script>
{% endblock %}
</body>
</html>